package com.treeeroot.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitMQConnection {
    /**
     * 获取rabbitmq连接对象
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //2.设置连接virtual host  【设置的virtual host 在web上创建时就必须加上/】
        factory.setVirtualHost("/quicker");
        //3.1设置连接账号
        factory.setUsername("rabbit");
        //3.2设置连接密码
        factory.setPassword("123456");
        //4.1设置连接地址
        factory.setHost("127.0.0.1");
        //4.2设置连接端口号
        factory.setPort(5672);
        return factory.newConnection();
    }
}
